package com.ll.beautymall.adapter;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ll.beautymall.R;
import com.ll.beautymall.bean.Brand;
import com.ll.beautymall.ui.home.brand.BrandActivity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/10/24.
 */
public class BrandAdapter extends BaseAdapter {
    private List<String> images;
    private List<Brand> brandList;

    public void setData(List<String> list) {
        this.images = list;
        notifyDataSetChanged();
    }

    public void addData(List<String> list) {
        this.images.addAll(list);
        notifyDataSetChanged();
    }

    public void setBrandList(List<Brand> brandList) {
        this.brandList = brandList;
    }

    public void removeData(List<String> list) {
        this.images.removeAll(list);
        notifyDataSetChanged();
    }

    public BrandAdapter() {

    }

    @Override
    public int getCount() {
        return images != null ? images.size() : 0;
    }

    @Override
    public Object getItem(int i) {
        return images != null ? images.get(i) : null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, final ViewGroup viewGroup) {
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.gv_item_brands, viewGroup, false);
        ImageView iv_cover = (ImageView) view.findViewById(R.id.iv_brand_cover);
        Picasso.with(viewGroup.getContext()).load(images.get(i)).into(iv_cover);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Brand brand = brandList.get(i);
                Intent intent = new Intent(viewGroup.getContext(), BrandActivity.class);
                intent.putExtra("brand", brand);
                viewGroup.getContext().startActivity(intent);
            }
        });
        return view;
    }
}
